<?php

namespace app\controllers;


use Yii;
use yii\helpers\Json;

class JsapiController extends BaseController
{
    protected $jsApiList = [
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'onMenuShareQZone',
        'startRecord',
        'stopRecord',
        'onVoiceRecordEnd',
        'playVoice',
        'pauseVoice',
        'stopVoice',
        'onVoicePlayEnd',
        'uploadVoice',
        'downloadVoice',
        'chooseImage',
        'previewImage',
        'uploadImage',
        'downloadImage',
        'translateVoice',
        'getNetworkType',
        'openLocation',
        'getLocation',
        'hideOptionMenu',
        'showOptionMenu',
        'hideMenuItems',
        'showMenuItems',
        'hideAllNonBaseMenuItem',
        'showAllNonBaseMenuItem',
        'closeWindow',
        'scanQRCode',
        'chooseWXPay',
        'openProductSpecificView',
        'addCard',
        'chooseCard',
        'openCard',
    ];

    public function actionIndex()
    {
        /** @var \zonday\weixin\Weixin $weixin */
        $weixin = Yii::$app->weixin;
        $request = Yii::$app->getRequest();
        $jsApiConfigJson = Json::encode($weixin->jsApiConfig($request->getAbsoluteUrl(), $this->jsApiList, ['debug' => true]));
        Yii::trace($request->getAbsoluteUrl());
        Yii::trace($weixin->getJsApiTicket());
        Yii::trace($jsApiConfigJson);
        return $this->render('index', [
            'jsApiConfigJson' => $jsApiConfigJson
        ]);
    }
}